/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using DOAN.DO;
/// <summary>
/// Summary description for CT_MonhocDAL
/// </summary>
namespace DOAN.DAL
{

    public class CT_MonhocDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public CT_MonhocDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(CT_MonhocDO objCT_MonhocDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Monhoc_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Mamonhoc", SqlDbType.VarChar);
            Sqlparam.Value = objCT_MonhocDO.Mamonhoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tentaikhoan", SqlDbType.VarChar);
            Sqlparam.Value = objCT_MonhocDO.Tentaikhoan;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(CT_MonhocDO objCT_MonhocDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Monhoc_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objCT_MonhocDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Mamonhoc", SqlDbType.VarChar);
            Sqlparam.Value = objCT_MonhocDO.Mamonhoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tentaikhoan", SqlDbType.VarChar);
            Sqlparam.Value = objCT_MonhocDO.Tentaikhoan;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public DataTable GetByMon(string tk)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCauHoi_GetByMon";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Mamon", SqlDbType.NChar);
            Sqlparam.Value = tk;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable Timkiem(string tk)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Monhoc_Tim";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Mamon", SqlDbType.NChar);
            Sqlparam.Value = tk;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable GetAllByUser(string tk)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_CT_Monhoc_GetAll";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@user", SqlDbType.NChar);
            Sqlparam.Value = tk;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable GetByUser(string tk)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_CT_Monhoc_GetByUser";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@user", SqlDbType.NChar);
            Sqlparam.Value = tk;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public int Delete(CT_MonhocDO objCT_MonhocDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Monhoc_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objCT_MonhocDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Monhoc_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public CT_MonhocDO Select(CT_MonhocDO objCT_MonhocDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Monhoc_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objCT_MonhocDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objCT_MonhocDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["Mamonhoc"]))
                    objCT_MonhocDO.Mamonhoc = Convert.ToString(dr["Mamonhoc"]);
                if (!Convert.IsDBNull(dr["Tentaikhoan"]))
                    objCT_MonhocDO.Tentaikhoan = Convert.ToString(dr["Tentaikhoan"]);

            }
            return objCT_MonhocDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Monhoc_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrCT_MonhocDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    CT_MonhocDO objCT_MonhocDO = new CT_MonhocDO();
                    if (!Convert.IsDBNull(dr["ID"]))
                        objCT_MonhocDO.ID = Convert.ToInt32(dr["ID"]);
                    if (!Convert.IsDBNull(dr["Mamonhoc"]))
                        objCT_MonhocDO.Mamonhoc = Convert.ToString(dr["Mamonhoc"]);
                    if (!Convert.IsDBNull(dr["Tentaikhoan"]))
                        objCT_MonhocDO.Tentaikhoan = Convert.ToString(dr["Tentaikhoan"]);
                    arrCT_MonhocDO.Add(objCT_MonhocDO);
                }
            }
            return arrCT_MonhocDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCT_Monhoc_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
